﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Phone
{
    public partial class Calling : Form
    {
        //默认构造函数
        public Calling()
        {
            InitializeComponent();
        }

        //窗体加载时显示正在呼叫的号码
        private void Calling_Load(object sender, EventArgs e)
        {
            switch (Vars.busy_sip_or_pstn)
            {
                case "sip":
                    label1.Text = Vars.sip?.GetRemoteUser();
                    break;
                case "pstn1":
                    label1.Text = Vars.pstn1?.GetRemoteUser();
                    break;
                case "pstn2":
                    label1.Text = Vars.pstn2?.GetRemoteUser();
                    break;
            }
        }

        //对方正在通话中
        public void busy()
        {
            if (label2.InvokeRequired)
            {
                label2.Invoke(new Action(() =>
                {
                    label2.Text = "对方正在通话中";
                }));
            }
            else
            {
                label2.Text = "对方正在通话中";
            }
        }

        //对方拒接
        public void decline()
        {
            if (label2.InvokeRequired)
            {
                label2.Invoke(new Action(() =>
                {
                    label2.Text = "对方拒接";
                }));
            }
            else
            {
                label2.Text = "对方拒接";
            }
        }

        //对方响铃
        public void ring()
        {
            if (label2.InvokeRequired)
            {
                label2.Invoke(new Action(() =>
                {
                    label2.Text = "对方响铃";
                }));
            }
            else
            {
                label2.Text = "对方响铃";
            }
        }

        //取消呼叫
        private void button1_Click(object sender, EventArgs e)
        {
            switch (Vars.busy_sip_or_pstn)
            {
                case "sip":
                    Vars.sip?.UserOptionSelect("Cancel");
                    break;
                case "pstn1":
                    Vars.pstn1?.UserOptionSelect("Cancel");
                    break;
                case "pstn2":
                    Vars.pstn2?.UserOptionSelect("Cancel");
                    break;
            }
        }
    }
}
